package com.dt76.smallloanbackendservice.controller.huxaun;


import com.dt76.smallloanbackendservice.pojo.huxuan.Vip;
import com.dt76.smallloanbackendservice.service.huxuan.SenderService;
import com.dt76.smallloanbackendservice.service.huxuan.VipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/vip")
public class VipController {

    @Autowired
    private VipService vipService;

    @Autowired
    private SenderService senderService;

    //查询所有会员信息
    @RequestMapping("/all")
    public List<Vip> qryAll(){
        return vipService.qryAll();
    }

    //修改会员等级全字段
    @RequestMapping("/updRankAll")
    public int updRankAll(){
        int num = vipService.updRankAll();
        System.out.println("修改会员等级："+num);
        return num;
    }
    @RequestMapping("/updRank")
    public  int updRank(@RequestBody Vip vip){
        int rankNum = vipService.updRank(vip);
        System.out.println(vip.toString());
        System.out.println("单个会员等级修改"+rankNum);
        return rankNum;
    }
    //删除
    @RequestMapping("/delVip")
    public void delVip(@RequestParam("id") int id){
         vipService.delVip(id);
    }
    //添加
    @RequestMapping("/addVip")
    public void addVip(@RequestBody Vip vip){
        vipService.addVip(vip);
    }
    //修改
    @RequestMapping("/updInfo")
    public void updInfo(@RequestBody Vip vip){
        vipService.updInfo(vip);
    }

    //发送邮件
    @RequestMapping("/email")
    public void sendEmail(@RequestParam("id") int id,
                          @RequestParam("email") String email){
        System.out.println("进入Service发送邮件");
    senderService.sendEmail(id,email);
    }
    //发送短信
    @RequestMapping("/sms")
    public void sendSMS(@RequestParam("id") int id,
                        @RequestParam("num") String num){
        System.out.println("进入Service发送短信");
        senderService.sendSMS(id,num);
    }

}
